package com.janwen.j2se.net;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.lang3.StringUtils;

public class FaultDemo {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        final String tudou = "http://v.youku.com/v_playlist/f17170661o1p9.html";
      Thread.dumpStack();
        URL url = new URL(tudou);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.connect();
        try {
            InputStream in = conn.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));
            StringBuilder buf = new StringBuilder();
            String line = null;
            int lines =0;
            int count = 0;
            int malloc = 0;
            while ((line = br.readLine()) != null) {
            	lines++;//1
                count+=line.length();//10+20
                malloc += count;//10+30
                if (StringUtils.isNotEmpty(buf.toString())) {
                    buf.append("\r\n");
                }
                buf.append(line);
            }
            //do something with 'buf'
            System.out.println(lines+" -> "+count+" -> "+malloc);
            Thread.dumpStack();
        } finally {
            conn.disconnect();
        }
        
    }

}
